<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{$lang.home}{if $ur_here} - {$ur_here} {/if}</title>
<meta name="Copyright" content="Douco Design." />
 <link href="templates/notify.css" rel="stylesheet" type="text/css">
<link href="templates/public.css" rel="stylesheet" type="text/css">

{include file="javascript.htm"}
 <script type="text/javascript" src="include/layer/layer.js"></script>
<script type="text/javascript" src="images/jquery.autotextarea.js"></script>
</head>
<body>
<div id="dcWrap">
 {include file="header.htm"}
 <div id="dcLeft">{include file="menu.htm"}</div>
 <div id="dcMain">
   {include file="ur_here.htm"}
   <div class="mainBox" style="{$workspace.height}">
    <!-- {if $rec eq 'default'} 通知模板类型 -->
    <h3>{$ur_here}</h3>



    <div id="list">
    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
     <tr>
      <th>通知类型</th>
      <th>状态</th>
      <th>操作</th>
     </tr>

     <tr>
      <td align="center">邮件通知</td>
      <td align="center">{if $site.email_notify eq '1'}已开启{else}未开启</i>{/if}</td>
      <td>
       <a href="notify.php?rec=op&type=email" class="btn">{if $site.email_notify eq '1'}关闭{else}开启{/if}</a>
       <a href="notify.php?rec=template&type=email" class="btn">用户通知模板</a>
       <a href="notify.php?rec=template&type=email&notify_type=business" class="btn">管理员通知模板</a>
      </td>
     </tr>
     <tr>
      <td align="center">短信通知</td>
      <td align="center">{if $site.sms_notify eq '1'}已开启{else}未开启{/if}</td>
      <td>
       <a href="notify.php?rec=op&type=sms" class="btn">{if $site.sms_notify eq '1'}关闭{else}开启{/if}</a>
       <a href="notify.php?rec=template&type=sms&notify_type=user" class="btn">用户通知模板</a>
       <a href="notify.php?rec=template&type=sms&notify_type=business" class="btn">管理员通知模板</a>
      </td>
     </tr>

    </table>
    </div>
    <div class="clear"></div>
    <!-- {/if} -->

    <!--{if $rec eq 'template'} 模板列表-->
    <!--当前选择的模板id-->
    <input type="hidden" id="curr_selectid" value="{$template_select.template_code}"/>
    <input type="hidden" id="notify_type" value="{$notify_type}">

    <!--{if $type eq 'email'} 邮件模板-->
    <h3>邮件通知模板</h3>
    <div class="clearfix" >
     <!--左侧模板列表开始-->
     <div class="left_main">
      <ul>
       <!--{foreach from=$template_list item=template}-->
       <a href="javascript:void(0);" onclick="template_onclick(this);" id="{$template.template_code}" style="text-decoration: none;">
        <li>{$template.template_name}
         <div class="onoffswitch" style="height: 20px;float: right">
          <input type="checkbox" {if $template.is_enable eq '1'}checked=""{/if} value="1" class="onoffswitch-checkbox" id="is_enable_{$template.template_code}" name="{$template.template_code}" onchange="check_change(this);">
          <label class="onoffswitch-label" for="is_enable_{$template.template_code}">
           <span class="onoffswitch-inner"></span>
           <span class="onoffswitch-switch"></span>
          </label>
         </div>
        </li>
       </a>
       <!--{/foreach}-->
      </ul>
     </div>
     <!--左侧模板列表结束-->

     <!--右侧模板内容开始-->
     <div class="right_main">
      <div class="main-top">您正在编辑<a href="javascript:;" id="update_nameid">{$template_select.template_name}</a>通知模板</div>
      <div class="title-item"><div class="email_title">邮件标题：</div>
       <input type="text" style="float:left;margin:5px;width:300px" id="template_titleid" value="{$template_select.template_title}"  class="inpMain"/>
       <a href="javascript:;"><div class="edit_bat">标题支持标签请从编辑器中复制</div></a></div>
      {if $notify_type eq 'business'}
      <div class="title-item"><div class="email_title">通知邮箱：</div>
       <input type="text" style="float:left;margin:5px !important;width:300px" id="notification_mode" value="{$template_select.notification_mode}" class="inpMain" /><a href="javascript:;">
        <div class="edit_bat">请输入通知人邮箱，多个邮箱之间用英文逗号“,”隔开</div></a></div>
      {/if}

      <div class="rightlist" id="user_variable" style="float: left; margin: 10px">
       <!--{foreach from=$template_item item=item_obj}-->
       <a onclick='item_onclick({$item_obj.id})'  class="btn">{$item_obj.item_name}</a>
       <!--{/foreach}-->
      </div>

      <script id="editor" type="text/plain" style="clear: both;">{$template_select.template_content}</script>

         <div style="padding:10px">
             <input type="button" name="submit" value="保存" class="btn" onclick="template_submit();" />
         </div>
     </div>
     <!--右侧模板内容结束-->
    </div>
    <!--{/if} 邮件模板结束-->

    <!--{if $type eq 'sms'} 短信模板-->
             <h3>短信通知模板</h3>
             <div class="clearfix" >
             <div class="col-sm-4 left_main">
             <ul>
             <!--{foreach from=$template_list item=template}-->
             <a href="javascript:void(0);" onclick="template_onclick(this);" id="{$template.template_code}" style="text-decoration: none;">
             <li>{$template.template_name}
         <div class="onoffswitch" style="height: 20px;float: right">
             <input type="checkbox" {if $template.is_enable eq '1'}checked=""{/if} value="1" class="onoffswitch-checkbox" id="is_enable_{$template.template_code}" name="{$template.template_code}" onchange="check_change(this);">
         <label class="onoffswitch-label" for="is_enable_{$template.template_code}">
             <span class="onoffswitch-inner"></span>
             <span class="onoffswitch-switch"></span>
             </label>
             </div>
             </li>
             </a>
             <!--{/foreach}-->
             </ul>
             </div>
             <div class="col-sm-5 right_main">
             <div class="main-top" style="border-bottom: 1px solid #E3E3E3;margin-bottom:10px">您正在编辑<a href="javascript:;" id="update_nameid">{$template_select.template_name}</a>通知模板</div>


         <div class="qianming"><div style="width:75px;float:left;height:30px;line-height:30px;width:80px;padding-left: 10px;">模板ID：</div><input type="text" name="" id="template_titleid" value="{$template_select.template_title}" style="margin-right: 15px;width:300px" class="inpMain"/></div>
         <div class="qianming"><div style="width:75px;float:left;height:30px;line-height:30px;width:80px;padding-left: 10px;">短信签名：</div><input type="text" name="" id="signNameid" style="margin-right: 15px;width:300px" value="{$template_select.sign_name	}" class="inpMain"/></div>
         {if $notify_type eq 'business'}
         <div class="qianming"><div style="width:75px;float:left;height:30px;line-height:30px;width:80px;padding-left: 10px;">接收号码：</div><input type="text" name="" id="notification_mode" value="{$template_select.notification_mode}" style="margin-right: 15px;width:300px" class="inpMain"/></div>
         {/if}
         <div class="bl">
             <div style="width:75px;float:left;height:30px;line-height:30px;width:80px;padding-left: 10px;">可用变量：</div>
         <div style="width:88%;float: left;font-size:13px;" id="user_variable">
             <!--{foreach from=$template_item item=item_obj}-->
             {$item_obj.replace_name}({$item_obj.item_name}),
             <!--{/foreach}-->
         </div></div>

             <div  style="padding:10px">
                 <input type="button" name="submit" value="保存" class="btn btn-lg btn-primary" onclick="template_submit();">
                 <a href="notify.php" class="btn">返回</a>
                 </div>
                 </div></div>
             </div>
    <!--{/if} 短信模板结束-->

    <!--{/if}-->

             <!--{if $rec eq 'template'}-->
             <!--{if $type eq 'email'}-->

      <script type="text/javascript" src="include/ueditor/ueditor.config.js"></script>
      <script type="text/javascript" src="include/ueditor/ueditor.all.js"></script>
      <script>
          var $template_array={$template_list_json};
          var $template_send_item={$template_item_json};
          var notify_type = '{$notify_type}'; //模板类型
          {literal}
          var ue = UE.getEditor('editor',{
              initialFrameHeight : 320,
              initialFrameWidth : 730
          });
          var $is_first=0;
          var $curr_select=$("#curr_selectid").val();
          var index;
          /**
           * 左边模板菜单的点击函数
           */
          function template_onclick(event){

              $(event).parent('ul').find('a').removeClass('active');
              $(event).addClass('active');
              //处理新的以前 将上次改动的保存
              var $deal_type="";
              var $deal_title="";
              var $deal_content="";
              var ue = UE.getEditor('editor');
              if($is_first==0){
                  $deal_type=$("#curr_selectid").val();
                  $deal_title=$("#template_titleid").val();
                  $deal_content=ue.getContent();
                  $notification_mode = $("#notification_mode").val();
              }
              $template_type=$(event).attr("id");
              for($i=0; $i<$template_array.length;$i++){
                  $template_obj=$template_array[$i];
                  $template_obj_type=$template_obj.template_code;
                  if($template_obj_type==$deal_type && $is_first==0){
                      $template_array[$i].template_title=$deal_title;
                      $template_array[$i].template_content=$deal_content;
                      $template_array[$i].notification_mode=$notification_mode;
                  }

                  //如果相同相同模板
                  if($template_obj_type==$template_type){
                      $("#curr_selectid").val($template_type);
                      $("#update_nameid").text($template_obj.template_name);
                      $title=$template_obj.template_title;
                      $("#template_titleid").val($title);
                      $content=$template_obj.template_content;
                      ue.setContent($content, false);
                      $notification_mode_ext =$template_obj.notification_mode;
                      $("#notification_mode").val($notification_mode_ext);
                  }
              }
              $is_first=0;
              get_template_item($template_type);
          }

          function get_template_item($template_code){

              $.ajax({
                  type : "post",
                  url: 'notify.php?rec=get_template_item',
                  data: {"template_code": $template_code },
                  async : false, // 让它同步执行
                  success: function (data) {
                      data = $.parseJSON(data);
                      $template_send_item = data;
                      var $html="";
                      for($i=0;$i<data.length;$i++){
                          $id=data[$i]["id"];
                          $name=data[$i]["item_name"];
                          $replace=data[$i]["replace_name"];
                          $item_html="  <a onclick='item_onclick("+$id+");' class='btn' style='margin-bottom: 10px'>";
                          $item_html=$item_html+$name;
                          $item_html=$item_html+"</a>";
                          $html=$html+$item_html;
                      }
                      $("#user_variable").html($html);
                  }
              });
          }
          /**
           * 选择项的点击事件
           */
          function item_onclick($item_id){
              for($i=0;$i<$template_send_item.length;$i++){
                  $id=$template_send_item[$i].id;
                  if($id==$item_id){
                      var ue = UE.getEditor('editor');
                      var $content=ue.getContent();
                      $content=$content+$template_send_item[$i].show_name;
                      ue.setContent($content, false);  //赋值给UEditor
                      return false;
                  }
              }
          }
          //开启这个开关
          function check_change(event){
              var $type=$(event).attr("name");
              var $selected=$(event).is(':checked');
              var $is_enable=0;
              if($selected){
                  $is_enable =1;
              }else if($selected){
                  $is_enable=0;
              }
              for($i=0; $i<$template_array.length;$i++){
                  $template_obj=$template_array[$i];
                  $template_obj_type=$template_obj.template_code;
                  if($template_obj_type==$type){
                      $template_array[$i].is_enable=$is_enable;
                  }
              }
          }

          function template_submit(){
              var $curr_select=$("#curr_selectid").val();
              $("#"+$curr_select).click();
              $.ajax({
                  type : "post",
                  url: "notify.php?rec=update",
                  data: { "type": "email", "template_data": JSON.stringify($template_array),"notify_type":notify_type },
                  async : false, // 让它同步执行
                  beforeSubmit: function () {
                      index = layer.load(2, {
                          shade: [0.8, '#fff'] //0.1透明度的白色背景
                      });
                  },
                  success: function (data) {
                      layer.close(index);
                      layer.msg('恭喜您，更新成功！');
                  }
              });
          }

          {/literal}
      </script>
      <!--{/if}-->

      {if $type eq 'sms'}
      <script>
          var $template_array={$template_list_json};
          var $template_send_item={$template_item_json};
          var notify_type = '{$notify_type}'; //模板类型
          var $is_first=1;
          var $curr_select=$("#curr_selectid").val();
          $("#"+$curr_select).click();

          var index;
          /**
           * 左边模板菜单的点击函数
           */
          {literal}
          function template_onclick(event){
              $(event).parent('ul').find('a').removeClass('active');
              $(event).addClass('active');
              //处理新的以前 将上次改动的保存
              var $deal_type="";
              var $deal_title="";
              var $sign_name="";
              if($is_first==0){
                  $deal_type=$("#curr_selectid").val();
                  $deal_title=$("#template_titleid").val();
                  $sign_name=$("#signNameid").val();
                  $notification_mode=$("#notification_mode").val();
              }
              $template_type=$(event).attr("id");
              for($i=0; $i<$template_array.length;$i++){
                  $template_obj=$template_array[$i];
                  $template_obj_type=$template_obj.template_code;
                  if($template_obj_type==$deal_type && $is_first==0){
                      $template_array[$i].template_title=$deal_title;
                      $template_array[$i].sign_name=$sign_name;
                      $template_array[$i].notification_mode=$notification_mode;
                  }
                  if($template_obj_type==$template_type){
                      $("#curr_selectid").val($template_type);
                      $("#update_nameid").text($template_obj.template_name);
                      $title=$template_obj.template_title;
                      $("#template_titleid").val($title);
                      $("#signNameid").val($template_obj.sign_name);
                      $("#notification_mode").val($template_obj.notification_mode);
                  }

              }
              $is_first=0;
              get_template_item($template_type);
          }
          function get_template_item($template_code){
              $.ajax({
                  type : "post",
                  url: 'notify.php?rec=get_template_item',
                  data: {"template_code": $template_code },
                  async : false, // 让它同步执行
                  success: function (data) {
                      data = $.parseJSON(data);
                      var $html="";
                      for($i=0;$i<data.length;$i++){
                          $name=data[$i]["item_name"];
                          $replace=data[$i]["replace_name"];
                          if($html==""){
                              $html="  <a href='javascript:void(0)' class='btn' style='margin-bottom: 10px'>"+$replace+"("+$name+")</a>";
                          }else{
                              $html=$html+"  <a href='javascript:void(0)' class='btn' style='margin-bottom: 10px'>"+$replace+"("+$name+")</a>";
                          }
                      }
                      $("#user_variable").html($html);
                  }
              });
          }
          /**
           * 开关关闭的点击事件
           */
          function check_change(event){
              var $type=$(event).attr("name");
              var $selected=$(event).is(':checked');
              var $is_enable=0;
              if($selected){
                  $is_enable =1;
              }else if($selected){
                  $is_enable=0;
              }
              for($i=0; $i<$template_array.length;$i++){
                  $template_obj=$template_array[$i];
                  $template_obj_type=$template_obj.template_code;
                  if($template_obj_type==$type){
                      $template_array[$i].is_enable=$is_enable;
                  }
              }
          }
          function template_submit(){
              var $curr_select=$("#curr_selectid").val();
              $("#"+$curr_select).click();
              $.ajax({
                  type : "post",
                  url: "notify.php?rec=update",
                  data: { "type": "sms", "template_data": JSON.stringify($template_array),'notify_type':notify_type },
                  async : false, // 让它同步执行
                  beforeSubmit: function () {
                      index = layer.load(2, {
                          shade: [0.8, '#fff'] //0.1透明度的白色背景
                      });
                  },
                  success: function (data) {
                      data = $.parseJSON(data);
                      layer.close(index);
                      layer.msg('恭喜您，更新成功！');

                  }
              });
          } {/literal}
      </script>

      {/if}
      <!--{/if}-->
</body>
</html>